<script setup>
import { ref, onMounted, computed } from 'vue'
import { getDatailHotAPI } from '@/apis/detail'
import { useRoute } from 'vue-router'

//通过父组件传过来的type类型 判断执行什么操作
const props = defineProps({
  type: {
    type: Number,
    dafault: 1
  }
})

console.log(props.type)

//定义一个对象

const TYPEMAP = {
  1: '24小时热榜',
  2: '周热榜'
}

//计算属性监听传过来的type类型  
const title = computed(() => TYPEMAP[props.type])

const route = useRoute()
const goodList = ref([])

const getDetailHotLIst = async () => {

  const { result } = await getDatailHotAPI({
    id: route.params.id,
    type: props.type
  })

  goodList.value = result
  console.log(result)

}

onMounted(() => getDetailHotLIst())

</script>


<template>
  <div class="goods-hot">
    <h3>{{title}}</h3>
    <!-- 商品区块 -->
    <RouterLink :to="`/Detail/${item.id}`" .class="goods-item" v-for="item in goodList" :key="item.id">
      <img :src="item.picture" alt="" />
      <p class="name ellipsis pstyle">{{item.name}}</p>
      <p class="desc ellipsis">{{item.desc}}</p>
      <p class="price">&yen;{{ item.price }}</p>
    </RouterLink>
  </div>
</template>


<style scoped lang="scss">
.goods-hot {
  background-color: #fff;
  text-align: center;
  margin-bottom: 20px;
  h3 {
    height: 70px;
    background: $helpColor;
    color: #fff;
    font-size: 18px;
    line-height: 70px;
    padding-left: 25px;
    font-weight: normal;
  }
  .goods-item {
    color: red;
  }
  .pstyle {
    color: #333;
  }

  img {
    width: 160px;
    height: 160px;
    margin: 20px auto;
    display: block;
  }

  p {
    padding-top: 10px;
    padding-left: 20px;
    padding-right: 20px;
  }

  .name {
    font-size: 16px;
  }

  .desc {
    color: #999;
    height: 29px;
  }

  .price {
    color: $priceColor;
    font-size: 20px;
    padding-bottom: 20px;
  }
}
</style>